#pragma once
#include "request_handler.h"
#include <event2/buffer.h>
#include <event2/http.h>
#include <ctime>
#include <sstream>
#include <iomanip>
namespace http_dispacher {
	namespace handlers {
		class HelloHandler : public RequestHandler {
        public:
            void handleRequest(struct evhttp_request* req) override {
                std::time_t temp = time(0);
                auto tm = *std::localtime(&temp);
                std::stringstream transTime;
                transTime << std::put_time(&tm, "%Y-%m-%dT%H:%M:%S");

                struct evbuffer* buf = evbuffer_new();
                std::string response_str;
                response_str.append("Hello, World! datetime>>");
                response_str.append(transTime.str());
                const char* response = response_str.c_str(); //"Hello, World!";
                evbuffer_add(buf, response, strlen(response));
                evhttp_send_reply(req, HTTP_OK, "OK", buf);
                evbuffer_free(buf);
            }
		};
	}
}